#pragma once

#include <pthread.h>

namespace quitesix
{
    class Mutex
    {
    public:
        Mutex()
        {
            pthread_mutex_init(&_lock, nullptr);
        }
        ~Mutex()
        {
            pthread_mutex_destroy(&_lock);
        }
        void Lock()
        {
            pthread_mutex_lock(&_lock);
        }
        void Unlock()
        {
            pthread_mutex_unlock(&_lock);
        }

    private:
        pthread_mutex_t _lock;
    };

    class MutexGuard
    {
    public:
        MutexGuard(Mutex *mutex) :_mutex(mutex)
        {
            _mutex->Lock();
        }
        ~MutexGuard()
        {
            _mutex->Unlock(); 
        }
    private:
        Mutex *_mutex;
    };
}